/*************************************************************************
 *  Copyright © 2023-2030 FXB CO.,LTD. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：UPMProject
 *  文件：PackageUtilityClass.cs
 *  作者：Administrator
 *  日期：2025/7/25 10:40:2
 *  功能：Nothing
*************************************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.GlobalIllumination;

namespace SVNPackageManager.Editor
{
    public class PackageUtilityClass
    {
        /// <summary>
        /// 创建一张纯色贴图
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public static Texture2D CreateTexture(int width, int height, Color color)
        {
            Texture2D texture = new Texture2D(width, height);
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    texture.SetPixel(w, h, color);
                }
            }
            texture.Apply();

            return texture;
        }

        public static void DrawLine(Color color, Vector2 p1, Vector2 p2)
        {
            Handles.color = color;
            Handles.DrawLine(p1, p2);
        }

        public static void DrawLineHorizantal_Top(Color color, float p1XOffset = 0, float p2XOffset = 0, float yOffset = 0)
        {
            Rect lineRect = GUILayoutUtility.GetLastRect();
            Handles.color = color;
            Handles.DrawLine(new Vector2(lineRect.x + p1XOffset, lineRect.y + yOffset), new Vector2(lineRect.x + lineRect.width + p2XOffset, lineRect.y + yOffset));
        }

        public static void DrawLineHorizantal_Bottom(Color color, float p1XOffset = 0, float p2XOffset = 0, float yOffset = 0)
        {
            Rect lineRect = GUILayoutUtility.GetLastRect();
            Handles.color = color;
            Handles.DrawLine(new Vector2(lineRect.x + p1XOffset, lineRect.y + lineRect.height + yOffset), new Vector2(lineRect.x + lineRect.width + p2XOffset, lineRect.y + lineRect.height + yOffset));
        }

        public static void DrawLineVertical_Left(Color color, float p1YOffset = 0, float p2YOffset = 0, float xOffset = 0)
        {
            Rect lineRect = GUILayoutUtility.GetLastRect();
            Handles.color = color;
            Handles.DrawLine(new Vector2(lineRect.x + xOffset, lineRect.y + p1YOffset), new Vector2(lineRect.x + xOffset, lineRect.y + lineRect.height + p2YOffset));
        }

        public static void DrawLineVertical_Right(Color color, float p1YOffset = 0, float p2YOffset = 0, float xOffset = 0)
        {
            Rect lineRect = GUILayoutUtility.GetLastRect();
            Handles.color = color;
            Handles.DrawLine(new Vector2(lineRect.x + lineRect.width + xOffset, lineRect.y + p1YOffset), new Vector2(lineRect.x + lineRect.width + xOffset, lineRect.y + lineRect.height + p2YOffset));
        }
    }
}


